//
//  LGLungFollowEditTaskHeader.m
//  HeartDiseaseManage
//
//  Created by 1234 on 2024/7/8.
//

#import "LGLungFollowEditTaskHeader.h"

@interface LGLungFollowEditTaskHeader()<UITextFieldDelegate>
/**   */
@property (nonatomic , strong)UILabel *titleLabel;
/**   */
@property (nonatomic , strong)UIView *guideView;
/**   */
@property (nonatomic , strong)UILabel *dayTitle;
@property (nonatomic , strong)UITextField *dayTF;
/**   */
@property (nonatomic , strong)UILabel *typeTitle;
@property (nonatomic , strong)UIButton *typeBtn;
/**   */
@property (nonatomic , strong)UIView *lineView;

@end

@implementation LGLungFollowEditTaskHeader

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self createSubView];
    }
    return self;
}

-(void)setIndex:(NSInteger)index{
    _index = index;
}

-(void)setCandelete:(BOOL)candelete{
    _candelete = candelete;
    self.guideView.hidden = candelete;
}

-(void)setDataDic:(NSDictionary *)dataDic{
    _dataDic = dataDic;
    self.titleLabel.text = [NSString stringWithFormat:@"NO.%ld距离基线 %@ 天",self.index,dataDic[@"days"]];
    self.dayTF.text = LGNSString(dataDic[@"days"]);
    [self.typeBtn setTitle:LGNSString(dataDic[@"task_type_name"]) forState:UIControlStateNormal];
}


-(void)textFieldDidEndEditing:(UITextField *)textField{
    if (self.delegate && [self.delegate respondsToSelector:@selector(editTaskDays:section:)]) {
        [self.delegate editTaskDays:textField.text section:self.index];
    }
}

//删除
-(void)deleteButtonAction{
    if (self.delegate && [self.delegate respondsToSelector:@selector(deleteFollowUp:)]) {
        [self.delegate deleteFollowUp:self.index];
    }
}

//随访类型
-(void)selectTypeAction{
    if (self.delegate && [self.delegate respondsToSelector:@selector(selectTaskType:)]) {
        [self.delegate selectTaskType:self.index];
    }
}

#pragma mark
#pragma mark ====> 创建控件
-(void)createSubView{
    self.topMargin = viewPix(8);
    UIImageView *iconView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"肺癌随访-名称"]];
    iconView.frame = CGRectMake(viewPix(28), viewPix(26), viewPix(24), viewPix(24));
    [self addSubview:iconView];
    [self addSubview:self.titleLabel];
    UIButton *deleteBtn = [UIButton buttonWithTitle:@" 删除" titleFont:LGFont(14) textColor:@"#DD3030" imageName:@"deleteRed12"];
    [deleteBtn addBorder:@"#DD3030" lineWidth:1 cornerRidus:viewPix(14)];
    deleteBtn.clipsToBounds = NO;
    [deleteBtn addTarget:self action:@selector(deleteButtonAction) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:deleteBtn];
    [self addSubview:self.guideView];
    [deleteBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self).offset(-viewPix(28));
        make.width.equalTo(@(viewPix(77)));
        make.height.equalTo(@(viewPix(28)));
        make.centerY.equalTo(iconView);
    }];
    
    [self.guideView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.equalTo(deleteBtn).offset(-1);
        make.width.height.equalTo(deleteBtn).offset(2);
    }];
    
    [self addSubview:self.dayTitle];
    [self addSubview:self.dayTF];
    [self addSubview:self.typeTitle];
    [self addSubview:self.typeBtn];
    [self addSubview:self.lineView];
    
}

-(UILabel *)titleLabel{
    if(!_titleLabel){
        _titleLabel = [UILabel lableWithText:@"" colorString:@"#333333" textFont:LGFontWeight(16, UIFontWeightMedium) textAlignment:NSTextAlignmentLeft lines:1];
        _titleLabel.frame = CGRectMake(viewPix(60), viewPix(28), Screen_W-viewPix(200), viewPix(24));
    }
    return _titleLabel;
}

-(UILabel *)dayTitle{
    if(!_dayTitle){
        _dayTitle = [UILabel lableWithText:@"距离基线(天)" colorString:@"#282828" textFont:LGFont(16) textAlignment:NSTextAlignmentLeft lines:1];
        _dayTitle.frame = CGRectMake(viewPix(28), viewPix(64), viewPix(100), viewPix(40));
    }
    return _dayTitle;
}

-(UITextField *)dayTF{
    if(!_dayTF){
        _dayTF = [[UITextField alloc]initWithFrame:CGRectMake(viewPix(128), viewPix(64), Screen_W-viewPix(156), viewPix(40))];
        [_dayTF addBorder:@"#EEEEEE" lineWidth:1 cornerRidus:3];
        _dayTF.tintColor = [UIColor colorWithString:@"#282828"];
        _dayTF.textColor = [UIColor colorWithString:@"#282828"];
        _dayTF.textAlignment = NSTextAlignmentLeft;
        _dayTF.keyboardType = UIKeyboardTypeNumberPad;
        _dayTF.placeholder = @"请输入";
        _dayTF.font = LGFont(16);
        _dayTF.delegate = self;
        _dayTF.leftViewMode = UITextFieldViewModeAlways;
        _dayTF.leftView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, viewPix(12), viewPix(40))];
    }
    return _dayTF;
}

-(UILabel *)typeTitle{
    if(!_typeTitle){
        _typeTitle = [UILabel lableWithText:@"随访类型" colorString:@"#282828" textFont:LGFont(16) textAlignment:NSTextAlignmentLeft lines:1];
        _typeTitle.frame = CGRectMake(viewPix(28), viewPix(120), viewPix(100), viewPix(40));
    }
    return _typeTitle;
}

-(UIButton *)typeBtn{
    if(!_typeBtn){
        _typeBtn = [UIButton buttonWithTitle:@"" titleFont:LGFont(16) textColor:@"#282828" frame:CGRectMake(viewPix(128), viewPix(120), Screen_W-viewPix(156), viewPix(40))];
        _typeBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
        _typeBtn.titleEdgeInsets = UIEdgeInsetsMake(0, viewPix(12), 0, viewPix(30));
        [_typeBtn addBorder:@"#EEEEEE" lineWidth:1 cornerRidus:3];
        [_typeBtn addTarget:self action:@selector(selectTypeAction) forControlEvents:UIControlEventTouchUpInside];
        UIImageView *tipView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"grayTip16"]];
        [_typeBtn addSubview:tipView];
        [tipView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(_typeBtn).offset(-viewPix(12));
            make.centerY.equalTo(_typeBtn);
            make.width.height.equalTo(@(16));
        }];
    }
    return _typeBtn;
}
-(UIView *)lineView{
    if(!_lineView){
        _lineView = [[UIView alloc]initWithFrame:CGRectMake(viewPix(28), viewPix(176), Screen_W-viewPix(32), 0.5)];
        _lineView.backgroundColor = [UIColor colorWithString:@"#E8E8E8"];
    }
    return _lineView;
}

-(UIView *)guideView{
    if(!_guideView){
        _guideView = [[UIView alloc]init];
        _guideView.backgroundColor = [UIColor colorWithString:@"#FFFFFF" alpha:0.5];
    }
    return _guideView;
}

@end
